﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ECS.DAL.Entity;
using ECS.DAL.Component;
using ECS.Framework;

namespace E_ICS.E_ICS
{
    public partial class frmAddOtherInfo : Form
    {
        #region private properties
        private Main.frmMain2 main = null;
        private string _otherInfoItem = string.Empty;

        #endregion

        #region form events
        public frmAddOtherInfo(Main.frmMain2 _main)
        {

            InitializeComponent();
            main = _main;
        }
        private void frmAddOtherInfo_Load(object sender, EventArgs e)
        {
            SetScreen();
            try
            {
                loaddatadropdown();
                //comboBox1.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string value = string.Empty;
            try
            {
                if (GlobalVariable.flagfromfrmAddOtherInfo == 1)
                {
                    value = txtValue.Text;
                    if (!string.IsNullOrEmpty(value))
                    {
                        string[] array = new string[2] { cboCommentType.SelectedItem.ToString(), value };
                        ViewEditComment.Data_Key_id = cboCommentType.SelectedValue.ToString();
                        ViewEditComment.Data_Key = array[0];
                        ViewEditComment.Data_Value = array[1];
                    }
                    this.DialogResult = DialogResult.Yes;
                }
                else
                {
                    GlobalVariable.cerent = GlobalVariable.cerent + 1;
                    value = txtValue.Text;
                    if (!string.IsNullOrEmpty(value))
                    {
                        _otherInfoItem = cboCommentType.SelectedItem.ToString();
                        string[] array = new string[2] { _otherInfoItem, value };
                        main.getDataFromAddOtherInfo(array);
                        GlobalVariable.commenttype_id[GlobalVariable.cerent] = cboCommentType.SelectedValue.ToString();
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        #endregion

        #region private methods
        /// <summary>
        /// setResourse Value to UI
        /// </summary>
        private void SetScreen()
        {
            this.Text = CommonResourceString.GetResourseValue("scn_Add_Other_Info_Frm_name");
            label1.Text = CommonResourceString.GetResourseValue("scn_Add_Other_Info_label1");
            label5.Text = CommonResourceString.GetResourseValue("scn_Add_Other_Info_label5");
            btnSave.Text = CommonResourceString.GetResourseValue("scn_Add_Other_Info_BtnSave");
            btnCancel.Text = CommonResourceString.GetResourseValue("scn_Add_Other_Info_btnCancel");
        }
        public void loaddatadropdown()
        {
            CommentRecordComponent comp = new CommentRecordComponent();
            List<ComboItem> ddList = comp.GetCommentTypeListForDropdown();
            if (ddList != null && ddList.Count > 0)
            {
                cboCommentType.DataSource = ddList;
                cboCommentType.ValueMember = "value";
                cboCommentType.DisplayMember = "text";
            }
        }
        #endregion
    }
}
